/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package bo2s.controler;

import bo2s.DAO.UserDAO;
import bo2s.data.User;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author thanhap
 */
@WebServlet(name = "UpdateServlet", urlPatterns = {"/UpdateServlet"})
public class UpdateServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        User usd = new User();
        usd.setId(Integer.parseInt(request.getParameter("id")));
        usd.setUsername(request.getParameter("username"));
        usd.setPassword(request.getParameter("password"));
        usd.setFullname(request.getParameter("fullname"));
        usd.setEmail(request.getParameter("email"));
        usd.setPhone(request.getParameter("phone"));
        usd.setAddress(request.getParameter("address"));
        usd.setGender(request.getParameter("gender"));
        usd.setImage(request.getParameter("image"));
        usd.setRole(Integer.parseInt(request.getParameter("role")));
        UserDAO eb = new UserDAO();
        eb.update(usd);
        response.sendRedirect("template_admin/MGUser/managerUser.jsp");    
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }
}
